{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}

<div class="queue-capacity-container">
  <div class="panel panel-default">
    <div class="panel-heading">
      <div id="collapseQueueCapacityPanelBtn" href="#collapsibleQueueCapacityPanel" data-toggle="collapse" {{bind-attr class=":panel-title :collapsible-panel-btn view.isCapacityPanelCollapsed:collapsed"}}>
        Children Queue Capacites for Default Partition
        {{#if isAnyChildrenQueueCapacityDirty}}
          {{#if warnInvalidCapacity}}
            {{warning-info class="red" tooltip="Invalid queue total capacity"}}
          {{else}}
            {{warning-info class="yellow-warning" tooltip="Need refresh queues / restart RM"}}
          {{/if}}
        {{/if}}
        <a class="pull-right"><i {{bind-attr class=":fa view.isCapacityPanelCollapsed:fa-plus:fa-minus"}}></i></a>
      </div>
    </div>
    <div id="collapsibleQueueCapacityPanel" {{bind-attr class=":panel-collapse :collapse view.isCapacityPanelCollapsed::in"}}>
      <div class="panel-body">
        {{#if isOperator}}
          {{#unless isLeafQ}}
            <div class="row">
              <div class="col-md-2 col-sm-2">
                <label>Children</label>
              </div>
              <div class="col-md-5 col-sm-5">
                {{tooltip-label
                  label='Capacity'
                  message='The minimum guaranteed capacity as a percentage of total capacity that is allocated to the queue.'
                }}
              </div>
              <div class="col-md-5 col-sm-5">
                {{tooltip-label
                  label='Max Capacity'
                  message='The cap (maximum capacity) as a percentage of total capacity that this queue can utilize.'
                }}
              </div>
            </div>
            {{#each childQ in childrenQueues}}
              {{edit-queue-capacity queue=childQ warnInvalidTotalCapacity=warnInvalidCapacity}}
            {{/each}}
            <div class="row">
              <div class="col-md-2 col-sm-2">
                <label>Total Capacity</label>
              </div>
              <div class="col-sm-4 col-md-4">
                <div class="progress total-capacity-progress">
                  <div role="progressbar" {{bind-attr class=":progress-bar warnInvalidCapacity:progress-bar-danger:progress-bar-success" style="totalCapacityBarWidth"}}>
                    {{childrenQueuesTotalCapacity}}%
                  </div>
                </div>
              </div>
              <div class="col-md-3 col-sm-3">
                <label>Absolute Capacity of Cluster</label>
              </div>
              <div class="col-md-3 col-sm-3">
                <div class="progress total-capacity-progress">
                  <div role="progressbar" class="progress-bar progress-bar-success" {{bind-attr style="absoluteClusterBarWidth"}}>
                    {{absoluteClusterCapacity}}%
                  </div>
                </div>
              </div>
            </div>
            {{#if warnInvalidCapacity}}
              <div class="row">
                <div class="col-sm-6 col-md-6 col-md-offset-2 col-sm-offset-2">
                  <small class="text-danger">Total capacity must be equal to 100%</small>
                </div>
              </div>
            {{/if}}
            {{#if parentQueue}}
              <div class="row">
                <div class="col-md-10 col-sm-10">
                  <small><strong>For this queue:</strong> To edit capacity and maximum capacity at parent queue level</small>
                  <small>{{#link-to 'capsched.queuesconf.editqueue' parentQueue}}Click Here{{/link-to}}</small>
                </div>
              </div>
            {{/if}}
          {{else}}
            <div class="row">
              <div class="col-md-6 col-md-6">
                <label>Configured Capacity: </label>
                <span>{{content.capacity}}%</span>
              </div>
              <div class="col-md-5 col-md-5">
                <label>Configured Maximum Capacity: </label>
                <span>{{content.maximum_capacity}}%</span>
              </div>
            </div>
            <div class="row">
              <div class="col-md-4 col-sm-4">
                <label>Absolute Capacity of Cluster</label>
              </div>
              <div class="col-md-4 col-sm-4">
                <div class="progress total-capacity-progress">
                  <div role="progressbar" class="progress-bar progress-bar-success" {{bind-attr style="absoluteClusterBarWidth"}}>
                    {{absoluteClusterCapacity}}%
                  </div>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-10 col-sm-10">
                <small><strong>For this queue:</strong> To edit capacity and maximum capacity at parent queue level</small>
                <small>{{#link-to 'capsched.queuesconf.editqueue' parentQueue}}Click Here{{/link-to}}</small>
              </div>
            </div>
          {{/unless}}
        {{else}}
          <div class="row">
            <div class="col-md-6 col-md-6">
              <label>Configured Capacity: </label>
              <span>{{content.capacity}}%</span>
            </div>
            <div class="col-md-5 col-sm-5">
              <label>Configured Maximum Capacity: </label>
              <span>{{content.maximum_capacity}}%</span>
            </div>
          </div>
          <div class="row">
            <div class="col-md-10 col-sm-10">
              <label>Absolute Capacity of Cluster: </label>
              <span>{{absoluteClusterCapacity}}%</span>
            </div>
          </div>
        {{/if}}
      </div>
    </div>
  </div>
</div>
